<?php

// +----------------------------------------------------------------------

// | Description: 网络推广部---中台系统和EC外呼系统的接口对接页面

// +----------------------------------------------------------------------

// | Author: zl

// +----------------------------------------------------------------------



namespace app\crm\controller;


use app\admin\controller\ApiCommon;

use app\crm\model\Customer as CustomerModel;

use app\crm\model\CustomerConfig as CustomerConfigModel;

use app\crm\model\CustomerGrade as CustomerGradeModel;

use think\response\Json;

use think\facade\Db;

use app\shop\model\RefundPayModel;


class PayCeShi extends ApiCommon

{
    protected $customerModel;

    protected $customerConfigModel;

    /**

     * 用于判断权限

     * @permission 无限制

     * @allow 登录用户可访问

     * @other 其他根据系统设置

     **/

    public function initialize()

    {

        $action = [

            'permission' => ['ceshi_pay'],

            'allow' => ['users', 'info']

        ];

        event('CheckAuth',$action);

        $request = $this->request;

        $a = strtolower($request->action());



        $this->customerModel = new CustomerModel();

        $this->customerConfigModel = new CustomerConfigModel();

        if (!in_array($a, $action['permission'])) {

            parent::initialize();

        }

    }

    public function ceshi_pay()
    {
        echo "正式服务器测试支付接口";

        $pay_demo = new RefundPayModel();

        $key = $pay_demo->demo();

        $myParams = array();
        $myParams['charset'] = 'UTF-8';
        $myParams['method'] = 'ysepay.online.barcodepay';
        $myParams['partner_id'] = '826491772980273';
        $myParams['sign_type'] = 'RSA';
        $myParams['timestamp'] = date('Y-m-d H:i:s', time());
        $myParams['version'] = '3.0';
        $myParams['notify_url'] = $key['notify_url'];
        $biz_content_arr = array(
            "out_trade_no" => $pay_demo->datetime2string(date('Y-m-d H:i:s')),
            "shopdate" => $pay_demo->datetime2string(date('Ymd')),
            "subject" => "测试反扫",
            "total_amount" => "0.01",
            "seller_id" => '826491772980273',
            "seller_name" => '郑州市中原区嘉氏堂美容店',
            "timeout_express" => "24h",
            "business_code" => "00510030",
            // "bank_type" => "1903000",  //支付宝
            "bank_type" => "1902000",  //微信
            // "bank_type" => "9001002",  //中国银联
            // "bank_type" => "1905000",  //苏宁
            // "scene" => "bar_code",   //支付场景，支付宝时必填
            // "scene" => "wave_code",   //支付宝时必填
            "auth_code" => "134707877954377268",
            // "device_info" => "cs002356",  //终端设备号，中国银联时必填
        );
        $myParams['biz_content'] = json_encode($biz_content_arr, JSON_UNESCAPED_UNICODE);//构造字符串
        // ksort($myParams);
        // var_dump($myParams);

        
        $signStr = "";
        foreach ($myParams as $key => $val) {
            $signStr .= $key . '=' . $val . '&';
        }

        
        $signStr = rtrim($signStr, '&');
        
        //var_dump($this->common->);exit;
        $sign = $pay_demo->sign_encrypt(array('data' => $signStr));

        // echo "<pre>";
        // print_r($sign);
        // exit;

        $myParams['sign'] = trim($sign['check']);

        // var_dump($myParams);
        $result = $pay_demo->post_url($pay_demo->param['order_url'], $myParams, 'ysepay_online_barcodepay_response');

        // $result = '111';

        return $result;
    }

}